package com.augurit.wf.client.summary.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.wf.client.summary.web.form.WfTaskSummaryForm;
import com.augurit.wf.common.entity.Jbpm4HistProcinst;
import com.augurit.wf.common.entity.Jbpm4HistTask;
import com.augurit.wf.common.entity.WfBusInstance;
import com.augurit.wf.common.extmodel.SummaryCountNode;
public class WfTaskSummaryConvertor {
	
	public static List<WfTaskSummaryForm> convertBusSummaryList(List<Object[]> list) {
		if(list != null && list.size() > 0) {
			List<WfTaskSummaryForm> result = new ArrayList();
			
			for(Object[] objs : list){
				WfBusInstance inst  = (WfBusInstance)objs[0];
				Jbpm4HistProcinst proc = (Jbpm4HistProcinst)objs[1];
				String templateName = (String)objs[2];
				String templateTypeName = (String)objs[3];
				
				WfTaskSummaryForm form = new WfTaskSummaryForm();
				
				form.setTemplateName(templateName);
				form.setTemplateTypeName(templateTypeName);
				
				form.setBusMemo1(inst.getBusMemo1());
				form.setBusMemo2(inst.getBusMemo2());
				form.setBusMemo3(inst.getBusMemo3());
				form.setBusMemo4(inst.getBusMemo4());
				form.setBusMemo5(inst.getBusMemo5());
				form.setBusMemo6(inst.getBusMemo6());
				form.setBusMemo7(inst.getBusMemo7());
				form.setBusMemo8(inst.getBusMemo8());
				form.setBusMemo9(inst.getBusMemo9());
				form.setBusMemo10(inst.getBusMemo10());
				form.setBusDate1(inst.getBusDate1());
				form.setBusDate2(inst.getBusDate2());
				form.setBusDate3(inst.getBusDate3());
				form.setBusDate4(inst.getBusDate4());
				form.setBusNum1(inst.getBusNum1());
				form.setBusNum2(inst.getBusNum2());
				
				form.setProcDuedate(proc.getProcessDuedate());
				form.setProcEnddate(proc.getEnd());
				form.setProcStartdate(proc.getStart());
				form.setProcInstId(proc.getProcInstId());
				form.setWfBusInstanceId(inst.getWfBusInstanceId());
				
				
				result.add(form);
			}
			
			return result;
		}
		return null;
	}
	
	public static List<WfTaskSummaryForm> convertToTaskSummaryList(List<Object[]> list) {
		if(list != null && list.size() > 0) {
			List<WfTaskSummaryForm> result = new ArrayList();
			
			for(Object[] objs : list){
				Jbpm4HistTask task = (Jbpm4HistTask)objs[0];
				Jbpm4HistProcinst proc = (Jbpm4HistProcinst)objs[1];
				WfBusInstance inst = (WfBusInstance)objs[2];
				String templateName = (String)objs[3];
				String templateTypeName = (String)objs[4];

				WfTaskSummaryForm form = new WfTaskSummaryForm();
				
				form.setWfBusInstanceId(inst.getWfBusInstanceId());
				form.setMasterEntity(inst.getMasterEntity());
				form.setMasterEntityKey(inst.getMasterEntityKey());
				form.setProcInstId(inst.getProcInstId());
				form.setTemplateId(inst.getTemplateId());
				form.setBusMemo1(inst.getBusMemo1());
				form.setBusMemo2(inst.getBusMemo2());
				form.setBusMemo3(inst.getBusMemo3());
				form.setBusMemo4(inst.getBusMemo4());
				form.setBusMemo5(inst.getBusMemo5());
				form.setBusMemo6(inst.getBusMemo6());
				form.setBusMemo7(inst.getBusMemo7());
				form.setBusMemo8(inst.getBusMemo8());
				form.setBusMemo9(inst.getBusMemo9());
				form.setBusMemo10(inst.getBusMemo10());
				form.setBusDate1(inst.getBusDate1());
				//form.setBusDate2(inst.getBusDate2());
				form.setBusDate2(proc.getStart());
				form.setBusDate3(inst.getBusDate3());
				form.setBusDate4(inst.getBusDate4());
				form.setBusNum1(inst.getBusNum1());
				form.setBusNum2(inst.getBusNum2());
				
				form.setTaskInstDbid(task.getHistTaskInstDbid());
				form.setAgent(task.getAgent());
				form.setAgentName(task.getAgentName());
				form.setAssignee(task.getAssignee());
				form.setCreate(task.getCreate());
				form.setDuedate(task.getDuedate());
				form.setSignTime(task.getSignTime());
				form.setAgentStartDate(task.getAgentStartDate());
				form.setAgentEndDate(task.getAgentEndDate());
				form.setActivityName(task.getActivityName());
				form.setActivityChineseName(task.getActivityChineseName());
				
				form.setProcDuedate(proc.getProcessDuedate());
				form.setProcEnddate(proc.getEnd());
				form.setProcStartdate(proc.getStart());
				form.setProcInstId(proc.getProcInstId());
				
				form.setTemplateName(templateName);
				form.setTemplateTypeName(templateTypeName);
				
				result.add(form);
			}
			
			return result;
		}
		return null;
	}
	
//	public static List<WfTaskSummaryForm> convertVoListToFormList(List<WfTaskSummary> wfTaskSummaryList) {
//		if(wfTaskSummaryList != null && wfTaskSummaryList.size() > 0) {
//			List<WfTaskSummaryForm> wfTaskSummaryFormList = new ArrayList();
//			for(int i=0; i<wfTaskSummaryList.size(); i++) {
//				wfTaskSummaryFormList.add(convertVoToForm(wfTaskSummaryList.get(i)));
//			}
//			return wfTaskSummaryFormList;
//		}
//		return null;
//	}
	
//	public static List<WfTaskSummary> convertFormListToVoList(List<WfTaskSummaryForm> wfTaskSummaryFormList) {
//		if(wfTaskSummaryFormList != null && wfTaskSummaryFormList.size() > 0) {
//			List<WfTaskSummary> wfTaskSummaryList = new ArrayList();
//			for(int i=0; i<wfTaskSummaryFormList.size(); i++) {
//				WfTaskSummary wfTaskSummary = new WfTaskSummary();
//				convertFormToVo(wfTaskSummaryFormList.get(i), wfTaskSummary);
//				wfTaskSummaryList.add(wfTaskSummary);
//			}
//			return wfTaskSummaryList;
//		}
//		return null;
//	}
	
	public static List<SummaryCountNode> convertToExtModel(String groupByProperty, String templateTypeName, List<Object[]> list){
		if(list != null && list.size() > 0){
			List<SummaryCountNode> result = new ArrayList();

			for(Object[] objs : list){
				String groupByValue = (String)objs[0];
				Long groupByCount = (Long)objs[1];
				
				SummaryCountNode node = new SummaryCountNode();
				node.setTemplateTypeName(templateTypeName);
				SummaryCountNode.loadInfo(node, groupByProperty, groupByValue, groupByCount);
				
				result.add(node);
			}
			
			return result;
		}
		return null;
	}
	
//	public static void convertJbpm4TaskToSummary(Jbpm4Task task, WfTaskSummaryForm summary){
//		if(task != null && summary != null){
//			summary.setTaskInstDbid(task.getTaskInstDbid());
//			summary.setActivityName(task.getActivityName());
//			summary.setActivityChineseName(task.getActivityChineseName());
//		}
//	}
	
//	public static void convertTaskImplToSummary(TaskImpl task, WfTaskSummaryForm summary){
//		if(task != null && summary != null){
//			summary.setTaskInstDbid(task.getDbid());
//			summary.setActivityName(task.getActivityName());
//			summary.setActivityChineseName(task.getActivityChineseName());
//		}
//	}
	
//	public static void convertWfBusTemplateToSummary(WfBusTemplateForm template, WfTaskSummaryForm summary){
//		if(template != null && summary != null){
//			summary.setWfTemplateCode(template.getTemplateCode());
//			summary.setWfTemplateName(template.getTemplateName());
//			summary.setTemplateTypeName(template.getTemplateTypeName());
//			summary.setMasterEntity(template.getMasterEntity());
//		}
//	}
}